#!/usr/bin/env python
# --*-- coding:utf-8 --*--
# author:g-y-b time:2020/6/9

import matplotlib.pyplot as plt
from skimage import io
import numpy as np
from mpl_toolkits.mplot3d import Axes3D


def transfer_data(image_path):
    img = io.imread(image_path)
    points = []     # 存放图片中白色区域的点信息
    boundX = []      # 存放图片中白色区域的边界点信息
    boundY = []
    for x in range(img.shape[0]):
        for y in range(img.shape[1]):
            if img[x, y] == 255:
                points.append([x, y])  # 白色区域点
                # 判断是否为白色区域的边界
                if img[x - 1, y] == 0 or img[x + 1, y] == 0 or img[x, y - 1] == 0 or img[x, y + 1] == 0:
                    boundX.append(x)
                    boundY.append(y)
    return boundX, boundY

bound = []
fig = plt.figure()
ax = fig.add_subplot(1, 1, 1, projection='3d')
for i in range(1, 100):
    if i < 10:
        image_path = 'images/0' + str(i) + '.bmp'
    else:
        image_path = 'images/' + str(i) + '.bmp'
    bound_x, bound_y = transfer_data(image_path)
    bound.append([bound_x, bound_y])
    x_array = np.array((bound_x))
    y_array = np.array((bound_y))
    a = x_array.shape[0]
    z = [i] * a
    z_array = np.array((z))
    print(i)

    ax.plot(x_array, y_array, z_array, markersize=2)  # 画三维曲线
print(bound)
plt.show()
